package com.readbook.action;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.readbook.service.PermissonService;
import com.readbook.util.*;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;

@Controller
@RequestMapping("/permission")
public class permission {
    @Resource
    private PermissonService permissonService;


    /**
     * @author 牟明艳
     * @comments 保存用户权限
     * @time 2019年10月16日14:25:39
     */
    @RequestMapping("add_Userpermission.html")
    @ResponseBody
    public Map<String, Object> add_Userpermission(HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> remap = new HashMap<String, Object>();
        Map<String, Object> smap = new HashMap<String, Object>();
        String dlzh = request.getParameter("dlzh");
        String permission = request.getParameter("permission");
        smap.put("dlzh", dlzh);
        smap.put("permission", permission);
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        String addtime = df.format(new Date());
        smap.put("addtime", addtime);
        remap = permissonService.add_Userpermission(smap);
        return remap;
    }


    /**
     * @author 牟明艳
     * @comments 修改用户权限
     * @time 2019年10月16日14:45:36
     */
    @RequestMapping("edit_Userpermission.html")
    @ResponseBody
    public Map<String, Object> edit_Userpermission(HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> remap = new HashMap<String, Object>();
        Map<String, Object> smap = new HashMap<String, Object>();
        String dlzh = request.getParameter("dlzh");
        String permission = request.getParameter("permission");
        smap.put("dlzh", dlzh);
        smap.put("permission", permission);
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        String addtime = df.format(new Date());
        smap.put("addtime", addtime);
        remap = permissonService.edit_Userpermission(smap);
        return remap;
    }


    /**
     * @author 牟明艳
     * @comments 删除用户权限
     * @time 2019年10月16日15:19:11
     */
    @RequestMapping("removeUserpermission.html")
    @ResponseBody
    public Map<String, Object> removeUserpermission(HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> remap = new HashMap<String, Object>();
        Map<String, Object> smap = new HashMap<String, Object>();
        String dlzh = request.getParameter("dlzh");
        String permission = request.getParameter("permission");
        smap.put("dlzh", dlzh);
        smap.put("permission", permission);
        remap = permissonService.removeUserpermission(smap);
        return remap;
    }


    /**
     * @author 牟明艳
     * @comments 分页查询用户权限
     * @time 2019年10月16日15:21:33
     */
    @RequestMapping("search_Userpermission.html")
    @ResponseBody
    public Map<String, Object> search_Userpermission(HttpServletRequest request, HttpServletResponse response) {
        String dlzh = "";
        if (request.getParameter("dlzh") != null) {
            dlzh = request.getParameter("dlzh").toString().trim();
        }

        Map<String, Object> gmap = new HashMap<String, Object>();
        gmap.put("dlzh", dlzh);
        List<Map<String, Object>> list1 = permissonService.search_Userpermission(gmap);
        Map<String, Object> rmap = new HashMap<String, Object>();
        rmap.put("data", list1);
        return rmap;
    }

}
